#!/bin/bash
DIR=$(dirname $0)
PWDPATH=$(cd $DIR && pwd)


outputTypes(){
  echo "\033[32m ====> 生成@libs/*下的dist/types声明文件-start \033[0m"
  local num=1
  for childDirPath in $PWDPATH/*; do
    if [ -d "$childDirPath" ]; then
      if [ -f "$childDirPath/tsconfig.json" ]; then
        echo "\033[36m $num. $childDirPath \033[0m"
        cd $childDirPath && pnpm exec tsc --declaration --emitDeclarationOnly
        num=$((num+1))
      fi
    fi
  done
  echo "\033[32m ====> 生成@libs/*下的dist/types声明文件-end \033[0m"
}

checkTypes(){
  echo "\033[32m ====> 检查@libs/*下的typescript语法-start \033[0m"
  local num=1
  for childDirPath in $PWDPATH/*; do
    if [ -d "$childDirPath" ]; then
      if [ -f "$childDirPath/tsconfig.json" ]; then
        echo "\033[36m $num. $childDirPath \033[0m"
        cd $childDirPath && pnpm exec tsc --noEmit
        num=$((num+1))
      fi
    fi
  done
  echo "\033[32m ====> 检查@libs/*下的typescript语法-end \033[0m"
}

case "$1" in
outputTypes)
  $1
  exit 0
  ;;
checkTypes)
  $1
  exit 0
  ;;
*)
  echo $DIR
  echo 'Usage: {outputTypes | checkTypes}'
  ;;
esac
